﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xinkui.Entity.AutoGenerator;
using DataFrameworkAccess;
using Xinkui.Common;

namespace Xinkui.DataAccess.AutoGenerator {
    public partial class MessageSendBoxDataAccess {
        public List<MessageSendBox_Entity> ListSendBox(int pageSize, int pageIndex, int userId, out int total) {
            total = 0;
            try {
                int tempRecord = 0;
                if (pageIndex <= 0) pageIndex = 1;
                DataCommand cmd = DataCommandManager.GetDataCommand("Query.Message.ListSendMessage");
                cmd.SetParameterValue("@UserId", userId);
                cmd.SetParameterValue("@pageSize", pageSize);
                cmd.SetParameterValue("@pageIndex", pageIndex);
                cmd.SetParameterValue("@recordCount", tempRecord);
                List<MessageSendBox_Entity> pageList = cmd.ExecuteEntityList<MessageSendBox_Entity>();
                total = Convert.ToInt32(cmd.GetParameterValue("@recordCount"));
                return pageList;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }

            return new List<MessageSendBox_Entity>(0);
        }

        public bool DeleteMessage(int userId, int messageId) {
            bool succ = false;
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("Operator.Message.SendBox.Delete");
                cmd.SetParameterValue("@UserId", userId);
                cmd.SetParameterValue("@MessageID", messageId);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return succ;

        }



        public bool RepostMessage(int userId, int messageId, string msg) {
            bool succ = false;
            try {
                DataCommand cmd = DataCommandManager.GetDataCommand("Operator.Message.SendBox.Repost");
                cmd.SetParameterValue("@UserId", userId);
                cmd.SetParameterValue("@MessageID", messageId);
                cmd.SetParameterValue("@Message", msg);
                cmd.ExecuteNonQuery();
                succ = true;
            }
            catch (Exception ex) {
                ExceptionHelper.ProcessException(ex);
            }
            return succ;

        }
    }
}
